<template>
	<view class="sizePop">
		<view class="top">
			<image class="top-img" :src="obj.image" mode=""></image>
			<view class="top-right">
				<view class="top-right-title">
					{{obj.name}}
				</view>
				<view class="price">
					<view class="price-num">{{obj.price}}积分</view>
					<view class="price-num2">
						实际价格<text style="text-decoration: line-through;">￥{{obj.original_price}}</text>
					</view>
				</view>
				<view class="des">
					部分地区不包邮
				</view>
			</view>
		</view>
		<!-- <view class="size-color" v-for="(item,index) in arr" :key='index'> -->
		<view class="size-color" v-for="(item,index) in arr" :key='index'>
			<view class="size-color-box" style="margin-bottom: 40rpx;">
				<view class="color-title">
					{{item.spec_name}}
				</view>
				<view class="color-btn">
					<text :class="arr[index].showFlag==index2?'activeColor':'text'" v-for="(item2,index2) in item.spec_value" :key='index2' @click="clickColor(index2,index,item2)">{{item2.title}}</text>
				</view>
			</view>
		</view>
		<view class="num">
			<view style="font-size: 32rpx;font-weight: bold;color: #333333;">
				数量
			</view>
			<view class="num-right">
				<text @click="cut">-</text>
				<text class="addNum">{{num}}</text>
				<text @click="add">+</text>
			</view>
		</view>
		<view class="btn">
			<view class="btn-left" v-if="!test" @click="addShopCar(0)">
				加入购物车
			</view>
			<view class="btn-right" v-else @click="addShopCar(1)">
				立即兑换
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props:["test","sizeArr","obj"],
		data() {
			return {
				num:1,//数量默认为1
				isShow:false,//控制弹框
				isColor: -1, //选中颜色
				isSize: -1, //选尺寸
				arr:[],
			}
		},
		onLoad() {
		},
		watch:{
			sizeArr:{
				handler(n,o){
					// console.log(n,'监听的数据');
					this.arr = n
				},
				deep:true
			}
		},
		mounted() {
			this.arr = this.sizeArr
		},
		methods: {
			//加入购物车/立即兑换
			addShopCar(type){
				if(type==0){//加入购物车按钮
				   this.isShow = false;
				   this.$emit("send",this.isShow,this.num)
				   
				}else{//立即兑换按钮
					this.isShow = false;
					uni.navigateTo({
						url:'/myPackageA/mine/placeOrder/placeOrder'
					})
					this.$emit("send",this.isShow)
				}
			},
			//选择颜色
			clickColor(index,index2,item) {
				this.arr[index2].showFlag = index;
				console.log(item,'规格');
			},
			//数量加
			add(){
				this.num++;
				this.$store.dispatch("num",this.num);
			},
			//数量减
			cut(){
				this.num > 1 ? this.num -- : uni.showToast({title: '哎哟，只剩一件啦！', duration: 2000,icon:'none'});
				this.$store.dispatch("num",this.num);
				// console.log(this.$store.state.num,'取值');
			}
		}
	}
</script>

<style scoped lang="less">
	.btn {
		width: 100%;
		height: 88rpx;
		opacity: 1;
		border-radius: 44rpx;
		// position: fixed;
		// bottom: 0;
		// left: 0;
		display: flex;
		.btn-left{
			flex: 1;
			background: #FF7200;
			height: 100%;
			font-size: 28rpx;
			font-family: Source Han Sans CN;
			font-weight: 400;
			display: flex;
			justify-content: center;
			align-items: center;
			color: #FFFFFF;
			border-radius: 44rpx;
		}
		.btn-right{
			border-radius:44rpx;
			flex: 1;
			background-color: #FF0000;
			height: 100%;
			font-size: 28rpx;
			font-family: Source Han Sans CN;
			font-weight: 400;
			display: flex;
			justify-content: center;
			align-items: center;
			color: #FFFFFF;
		}
	}

	.num {
		display: flex;
		justify-content: space-between;
		padding-bottom: 150rpx;
		.addNum {
			margin: 0 10rpx;
			padding: 5rpx 20rpx;
			height: 26rpx;
			background: #D6D6D6;
			opacity: 1;
			line-height: 26rpx;
			text-align: center;
			font-size: 24rpx;
		}
	}

	.size-color {
		margin: 44rpx 0;

		.color-title {
			font-size: 32rpx;
			font-family: Source Han Sans CN;
			font-weight: bold;
			color: #333333;
		}

		.color-btn {
			margin-top: 40rpx;
			display: flex;
			justify-content: flex-start;
			flex-wrap: wrap;

			.activeColor {
				background: #FFC4C4;
				border: 2px solid #FF0000;
				border-radius: 28px;
				font-size: 28rpx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				color: #FF0000;
				margin-bottom: 20rpx;
				margin-right: 40rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				padding: 14rpx 20rpx;
			}

			.text {
				margin-bottom: 20rpx;
				margin-right: 40rpx;
				font-size: 28rpx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				color: #333333;
				display: flex;
				justify-content: center;
				align-items: center;
				background-color: #F2F2F2;
				padding: 14rpx 20rpx;
				border-radius: 28rpx;
			}
		}
	}

	.sizePop {
		width: 100%;
		height: 1000rpx;
	}

	.top {
		display: flex;
		justify-content: space-between;

		.top-img {
			width: 198rpx;
			height: 194rpx;
			border-radius: 20rpx;
		}

		.top-right {
			margin-left: 20rpx;
			flex: 1;

			.top-right-title {
				font-size: 36rpx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				color: #333333;
			}

			.price {
				display: flex;
				align-items: center;
				margin: 20rpx 0;

				.price-num {
					font-size: 32rpx;
					font-family: Source Han Sans CN;
					font-weight: 400;
					color: #FF0000;
				}

				.price-num2 {
					margin-left: 10rpx;
					font-size: 20rpx;
					font-family: Source Han Sans CN;
					font-weight: 400;
					color: #FF0000;
				}
			}

			.des {
				font-size: 24rpx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				line-height: 34rpx;
				color: #999999;
			}
		}
	}
</style>
